"""
数据库连接
"""
from pymysql import Connection

#1、建立数据库连接对象
conn = Connection(
    user="root",
    password="123456",
    host="localhost",
    database="mydb1",
    port=3306
)
# print(conn)
#2、创建游标对象
cursor = conn.cursor()
#3、游标方法执行sql
sql = "select * from userinfo"
result = cursor.execute(sql)
print(result)
#4、提交到数据库或者获取数据
query = cursor.fetchall()
print(query)
for item in query:
    print(item)
#5、关闭游标对象
cursor.close()
#6、关闭数据库连接
conn.close()